package com.event.demo.controller;

import com.event.demo.event.CustomEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

@RestController
public class EventController {
    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @RequestMapping("/push")
    public String push() {
        System.out.println("发送事件 Time：" +
                LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
        eventPublisher.publishEvent(new CustomEvent(this, "hello event"));
        return "push success";
    }
}
